from PIL import Image

# Load images
img1 = Image.open('C:\\Users\\crxc\\Pictures\\wandb\\论文2\\指定区域\\ours_wrap_with_rectangles.png')  # Replace with the correct file path
img2 = Image.open('C:\\Users\\crxc\\Pictures\\wandb\\论文2\\指定区域\\箭头\\ours_wrap_crop2_arrow.png')  # Replace with the correct file path
img3 = Image.open('C:\\Users\\crxc\\Pictures\\wandb\\论文2\\指定区域\\箭头\\ours_wrap_crop1_arrow.png')  # Replace with the correct file path


# Determine scale factor for second image
scaling_exponent = 1.6  # Change this to whatever scaling you need for img2
scale_factor_2 = scaling_exponent  # Simple scaling for example

# Resize second image
new_width_2 = int(img2.width * scale_factor_2)
new_height_2 = int(img2.height * scale_factor_2)
img2_resized = img2.resize((new_width_2, new_height_2), Image.ANTIALIAS)

# Determine scale factor for third image based on the new height of the second image
scale_factor_3 = new_height_2 / img3.height
new_width_3 = int(img3.width * scale_factor_3)
img3_resized = img3.resize((new_width_3, new_height_2), Image.ANTIALIAS)

# Create a new image with appropriate dimensions
gap = 10  # Gap between the images
new_img_width = img1.width
new_img_height = img1.height + new_height_2 + gap

# The position where the second image (bottom left) will be pasted
img2_position = (0, img1.height + gap)

# The position where the third image (bottom right) will be pasted
# It is aligned to the right of the first image
img3_position = (img1.width - new_width_3, img1.height + gap)

result_img = Image.new('RGB', (new_img_width, new_img_height), (255, 255, 255))

# Paste images into result image
result_img.paste(img1, (0, 0))
result_img.paste(img2_resized, img2_position)
result_img.paste(img3_resized, img3_position)

# # Save the result
# output_path = '/mnt/data/combined_image.png'  # replace with actual path
# result_img.save(output_path)

# Save the final image
output_path = 'C:\\Users\\crxc\\Pictures\\wandb\\论文2\\指定区域\\合成图\\out.png'  # Replace with your desired output path
result_img.save(output_path)